# coding=utf-8
import time

import traceback
from monthdelta import monthdelta
import datetime
import requests
from pymongo import MongoClient
import Utils
import sys
from pandas import DataFrame
import pandas as pd
import json

import pymongo
reload(sys)
sys.setdefaultencoding('utf-8')


mgClient = MongoClient('121.40.54.235', 27017,
    username='root2',
    password='Dream2015',
    authSource="stockDataStore",
    authMechanism='SCRAM-SHA-1')
db = mgClient['stockDataStore']

#my_collection.create_index([("mike", pymongo.DESCENDING),
'''                              # ("eliot", pymongo.ASCENDING)])
db.balance_sheet.create_index([('code', pymongo.ASCENDING)], name="index_code")
db.balance_sheet.create_index([('period', pymongo.ASCENDING)], name="index_period")
db.balance_sheet.create_index([('code', pymongo.ASCENDING), ('period', pymongo.ASCENDING)], name="index_code_period")
db.balance_sheet_profile.create_index([('code', pymongo.ASCENDING)], name="index_code")


db.profit_statement.create_index([('code', pymongo.ASCENDING)], name="index_code")
db.profit_statement.create_index([('period', pymongo.ASCENDING)], name="index_period")
db.profit_statement.create_index([('code', pymongo.ASCENDING), ('period', pymongo.ASCENDING)], name="index_code_period")
db.profit_statement_profile.create_index([('code', pymongo.ASCENDING)], name="index_code")


db.cash_flow.create_index([('code', pymongo.ASCENDING)], name="index_code")
db.cash_flow.create_index([('period', pymongo.ASCENDING)], name="index_period")
db.cash_flow.create_index([('code', pymongo.ASCENDING), ('period', pymongo.ASCENDING)], name="index_code_period")
db.cash_flow_profile.create_index([('code', pymongo.ASCENDING)], name="index_code")


db.stock_period_indices.create_index([('code', pymongo.ASCENDING)], name="index_code")
db.stock_period_indices.create_index([('period', pymongo.ASCENDING)], name="index_period")
db.stock_period_indices.create_index([('code', pymongo.ASCENDING), ('period', pymongo.ASCENDING)], name="index_code_period")



db.stock_daily_k.create_index([('code', pymongo.ASCENDING)], name="index_code")
db.stock_daily_k.create_index([('day', pymongo.ASCENDING)], name="index_day")
db.stock_daily_k.create_index([('code', pymongo.ASCENDING), ('day', pymongo.ASCENDING)], name="index_code_day")


'''
db.stock_top_shareholder.create_index([('code', pymongo.ASCENDING), ('category', pymongo.ASCENDING)], name="index_code")
db.stock_top_shareholder.create_index([('period', pymongo.ASCENDING), ('category', pymongo.ASCENDING)], name="index_period")
db.stock_top_shareholder.create_index([('name', pymongo.ASCENDING), ('category', pymongo.ASCENDING)], name="index_name")
db.stock_top_shareholder.create_index([('nature', pymongo.ASCENDING), ('category', pymongo.ASCENDING)], name="index_nature")
db.stock_top_shareholder.create_index([('code', pymongo.ASCENDING), ('period', pymongo.ASCENDING), ('category', pymongo.ASCENDING)], name="index_code_period")
db.stock_top_shareholder.create_index([('code', pymongo.ASCENDING), ('period', pymongo.ASCENDING), ('name', pymongo.ASCENDING), ('category', pymongo.ASCENDING)], name="index_code_period_name")


db.stock_shareholder_summary.create_index([('code', pymongo.ASCENDING), ('category', pymongo.ASCENDING)], name="index_code")
db.stock_shareholder_summary.create_index([('period', pymongo.ASCENDING), ('category', pymongo.ASCENDING)], name="index_period")
db.stock_shareholder_summary.create_index([('code', pymongo.ASCENDING), ('period', pymongo.ASCENDING), ('category', pymongo.ASCENDING)], name="index_code_period")



index_dict = db.stock_top_shareholder.index_information()
result = json.dumps(index_dict, ensure_ascii=False, indent=4, sort_keys=True)

print result
#print db.stock_daily_k.index_information()

